package com.ruoyi.crop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.crop.api.domain.CropType;
import com.ruoyi.crop.api.domain.SignRecord;
import com.ruoyi.crop.api.domain.Warehouse;
import com.ruoyi.crop.service.WarehouseService;
import com.ruoyi.crop.mapper.WarehouseMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 86178
* @description 针对表【src_warehouse(仓库表)】的数据库操作Service实现
* @createDate 2024-07-27 09:35:55
*/
@Service
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, Warehouse>
    implements WarehouseService{

    /**
     * 获取仓库列表
     */
    @Override
    public List<Warehouse> selectWarehouseList(Warehouse warehouse) {
        /*LambdaQueryWrapper<Warehouse> queryWrapper = new LambdaQueryWrapper<>();
        if (warehouse!=null){
            //仓库编号
            queryWrapper.eq(StringUtils.isNotBlank(warehouse.getWarehouseCode()),Warehouse::getWarehouseCode,warehouse.getWarehouseCode());
            //仓库名称
            queryWrapper.like(StringUtils.isNotBlank(warehouse.getWarehouseName()),Warehouse::getWarehouseName,warehouse.getWarehouseName());
            queryWrapper.orderByAsc(Warehouse::getWarehouseId);
        }*/
        return baseMapper.selectWarehouseList(warehouse);
    }

    @Override
    public List<SignRecord> getProductsById(Integer warehouseId) {
        return baseMapper.getProductsById(warehouseId);
    }

    /**
     * 校验仓库名称唯一
     * @param warehouse
     * @return
     */
    @Override
    public boolean checkWarehouseNameUnique(Warehouse warehouse) {
        LambdaQueryWrapper<Warehouse> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(warehouse.getWarehouseName()),Warehouse::getWarehouseName,warehouse.getWarehouseName());
        Warehouse one = this.getOne(queryWrapper);
        if (StringUtils.isNotNull(one)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}




